package com.example.demospirngdatamybatis.controller;


import com.example.demospirngdatamybatis.entity.Comment;
import com.example.demospirngdatamybatis.servcie.CommentServcie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/comments")
public class CommentController {
    @Autowired
    CommentServcie commentServcie;
    @GetMapping("/")
    public List<Comment> getAllComments(){
        return commentServcie.getAllComments();
    }

    @GetMapping("/{id}")
    public Comment getCommenttById(@PathVariable int id){
        return commentServcie.getCommenttById(id);
    }


    @PostMapping("/")
    public int addComment(@RequestBody Comment comment){
        return commentServcie.addComment(comment);
    }

    @DeleteMapping("/{id}")
    public int deleteCommentById(@PathVariable int id){
        return commentServcie.deleteCommentById(id);
    }
    @PutMapping("/")
    public int updateCommentById(@RequestBody Comment comment){
        return commentServcie.updateCommentById(comment);
    }
}
